extends Spatial

export (PackedScene) var Enemy
var mouse_pos 
var camera
var Enemy_array = Array()


func _ready():
	camera = $Player/Camera
	
	Enemy_array.append(Enemy.instance())
	add_child(Enemy_array[0])
	Enemy_array[0].translation = Vector3(0,1,-5)
func get_mouse_pos():
	var ray = $Player/Camera/RayCast
	var from = camera.project_ray_origin(get_viewport().get_mouse_position())-camera.translation
	var to = from+camera.project_local_ray_normal(get_viewport().get_mouse_position())*100
	ray.cast_to = to
	return(ray.get_collision_point())

func _physics_process(delta):
	mouse_pos = get_mouse_pos()

func _process(delta):
	$Player.move_and_slide($Player.walk(mouse_pos, delta), Vector3(0,1,0), true)
	for i in range(Enemy_array.size()):
		$Player.atack(Enemy_array[i].translation, mouse_pos)
	